<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>表单验证实验</title>
		<script src="js/jquery.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="css/bootstrap.min.css">
		<script>
			function checkSid(){
				// alert("周末好！");
				//取得学号
				sidvalue = document.getElementById("studentid").value;
				regExp=/^[0-9]{9}]$/;//正则表达式
				if(!regExp.test(sidvalue)){
					// alert("学号格式不对！");
					return false;
				}
				else{
					return true;
				}
			}
			function checkSname(){
				sname = document.getElementById("sname").value;
				regExp=/^[\u4E00-\u9FA5]{2,7}$/;
				if(!regExp.test(sname)){
					document.getElementById("snametip").innerHTML="姓名不合法！";
					document.getElementById("snametip").style="color:red;front-size=10px";
					return false;
				}
				else{
					document.getElementById("snametip").innerHTML="";
					return true;
				}
			}
			function checkMoble(){
				moble = document.getElementById("moble").value;
				regExp=/^^(17[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$$/;
				if(!regExp.test(moble)){
					document.getElementById("mobletip").innerHTML="手机号不合法！";
					document.getElementById("mobletip").style="color:red;front-size=10px";
					return false;
				}
				else{
					document.getElementById("mobletip").innerHTML="";
					return true;
				}
			}
			function checkSalary(){
				salary = document.getElementById("salary").value;
				regExp=/^^[0-9]{0,5}$$/;
				if(!regExp.test(salary)){
					document.getElementById("salarytip").innerHTML="薪资输入不合法！";
					document.getElementById("salarytip").style="color:red;front-size=10px";
					return false;
				}
				else{
					document.getElementById("salarytip").innerHTML="";
					return true;
				}
			}
		</script>
	</head>
	<body>
		<div class="center-block" style="width: 50%;">
			学号<input onblur="checkSid()" class="form-control" type="text" id="studentid" /><br />
			姓名<input onblur="checkSname()" class="form-control" type="text" id="sname" /><span id="snametip"></span><br />
			手机<input onblur="checkMoble()" class="form-control" type="text" id="moble" /><span id="mobletip"></span><br />
			薪资<input onblur="checkSalary()" class="form-control" type="text" id="salary" /><span id="salarytip"></span><br />
			<button class="btn btn-primary btn-block">添加学生</button>
		</div>
	</body>
</html>
	